﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.controllers.world {
    import net.wooga.pets.events.*;
    import net.wooga.pets.interfaces.*;
    import net.wooga.pets.constants.*;
    import org.robotlegs.mvcs.*;
    import net.wooga.pets.models.world.*;

    public class OnTreatmentFinalizedCommand extends Command {

        public var event:InfoEvent;
        public var world:WorldModel;

        override public function execute():void{
            var _local1:ITreatable = (this.world.getActor(this.event.id) as ITreatable);
            var _local2:Object = this.event.info.pet;
            var _local3:Boolean = ((_local2) && ((_local2.workflow_state == WorldConstants.BABY)));
            if (_local3){
                this.world.removeActor(_local1.id);
                dispatch(new InfoEvent(EventConstants.ON_HOSPITAL_LEFT, _local1.id));
                dispatch(new InfoEvent(EventConstants.CREATE_BABY, null, _local2));
                _local1 = (this.world.getActor(this.event.id) as ITreatable);
                _local1.moveToNextTarget(GameConstants.TYPE_KINDERGARTEN);
            } else {
                dispatch(new InfoEvent(EventConstants.SET_PATIENT, null, _local1));
            };
            var _local4:ITreatment = _local1.currentTreatment;
            var _local5:Object = this.event.info;
            _local4.finalize();
            dispatch(new InfoEvent(EventConstants.TREATMENT_STATUS_UPDATED, EventConstants.ON_TREATMENT_FINALIZED, _local4));
            dispatch(new InfoEvent(EventConstants.PATIENT_SPEECH_BUBBLE_UPDATE, this.event.id));
            var _local6:IRoom = (this.world.getRoomById(_local1.roomId) as IRoom);
            var _local7:ITreatment = _local1.currentTreatment;
            if (!_local7){
                _local1.state = WorldConstants.CURED;
            };
            if (((((_local5.hasOwnProperty(GameConstants.USER_DATA_CHANGES)) && (_local5.changes.hasOwnProperty(GameConstants.USER_LEVEL_INFO)))) && (_local5.changes.level_info.hasOwnProperty(GameConstants.USER_LEVEL_INFO_CURED_PETS)))){
                if ((_local5.changes.level_info.number_of_cured_pets % GameConstants.SHOW_LOST_PET_INTERVAL) == 0){
                    dispatch(new InfoEvent(EventConstants.CREATE_POPUP, GameConstants.LOST_PET_POPUP));
                };
            };
            dispatch(new InfoEvent(EventConstants.UPDATE_USER_DATA, null, _local5));
            dispatch(new InfoEvent(EventConstants.CREATE_REWARD_ICONS, _local6.id, _local5.items));
            dispatch(new InfoEvent(EventConstants.SHOW_THANK_YOU_ANI, null, _local1));
        }

    }
}//package net.wooga.pets.controllers.world 
